/*
 * @Author: xiaotiwen
 * @Date: 2020-06-03 15:30:05
 * @LastEditTime: 2020-07-17 16:43:30
 * @LastEditors: xiaotiwen
 * @FilePath: \eduweb\src\api\practiceManagement\scheduleSetting.js
 * @Description: 排课接口
 */

import fetch from 'common/src/utils/fetch';
import baseUrl from './env';
import UTILS from "common/src/utils/utils";

// 列表
export function getList(data) {
    return fetch({
        url: `${baseUrl}/udgPtClassInfo/querySchedule`,
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
// 排课明细保存
export function saveData(data) {
    return fetch({
        url: `${baseUrl}/udgPtClassInfo/editSchedule`,
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
// 发布后进行排课修改
export function editPublishSchedule(data) {
  return fetch({
    url: `${baseUrl}/udgPtClassInfo/editPublishSchedule`,
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data
  });
}
// 获取详情
export function getDetail(data) {
    return fetch({
        url: `${baseUrl}/udgPtClassInfo//getDetails?id=${data.id}`,
        method: 'get',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
// 上传文件
export function uploads(data) {
    return fetch({
        url: `${baseUrl}/udgPtClassInfo/uploadFile`,
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
// 发布
export function publicData(data) {
    return fetch({
        url: `${baseUrl}/udgPtClassInfo/publish`,
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
// 取消发布
export function cancelPublicData(data) {
    return fetch({
        url: `${baseUrl}/udgPtClassInfo/cancelPublish`,
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
// 排课保存
export function panelSave(data) {
    return fetch({
        url: `${baseUrl}/udgPtClassInfo/saveWeekSection`,
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
// 排课保存
export function saveRoomDetails(data) {
    return fetch({
        url: `${baseUrl}/udgPtClassInfo/saveRoomDetails`,
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
// 排课状态同步
export function classBorrow(data) {
    return fetch({
        url: `${baseUrl}/udgPtClassInfo/classBorrow`,
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
// 按钮（时间权限，是否）
export function btnSet(data) {
    return fetch({
        url: `${baseUrl}/udgPtSettingT/getSettingTime`,
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
// 排课
export function panelArrange(data) {
    return fetch({
        url: `/api/arrangementservice/manualArrange/practice`,
        // url: `/api/arrangementservice/manualArrange`,
        method: 'put',
        headers: {
            'Content-Type': 'application/json'
        },
        data
    });
}
//导出-实践教学阶段教学活动安排
export function exportArrange(data,name) {
    return fetch({
        url: `${baseUrl}/udgPtClassInfo/exportArrange`,
        method: "post",
        responseType: "blob",
        data
    }).then(res => {
        UTILS.downloadFile(
            res,
            name,
            "application/vnd.ms-excel;charset=utf-8"
        );
    });
}
//导出-各专业实践一览表
export function exportPractice(data) {
    return fetch({
        url: `${baseUrl}/udgPtClassInfo/exportPractice`,
        method: "post",
        responseType: "blob",
        data
    }).then(res => {
        UTILS.downloadFile(
            res,
            "各专业实践一览表",
            "application/vnd.ms-excel;charset=utf-8"
        );
    });
}
//导出-实践教学阶段任务表
export function exportFuns(data, name, url) {
    return fetch({
        url: `${baseUrl}/${url}`,
        method: "post",
        responseType: "blob",
        data
    }).then(res => {
        UTILS.downloadFile(
            res,
            name,
            "application/vnd.ms-excel;charset=utf-8"
        );
    });
}
//分散实习表或实习总结表单文件或打包下载
export function downloadZip(data, name) {
    return fetch({
        url: `${baseUrl}/udgPtAttachT/downloadZip`,
        method: "post",
        responseType: "blob",
        data
    }).then(res => {
        downloadFile(res, name);
    });
}
export function downloadFile(res, fileName) { // 下载 res 连接，fileName下载名称，fileType下载后文件类型
    if (fileName == null) {
        fileName = 'test.doc';
    }
    var blob = new Blob([res]);
    if ('download' in document.createElement('a')) {
        var downloadElement = document.createElement('a');
        var href = window.URL.createObjectURL(blob); // 创建下载的链接
        downloadElement.href = href;
        downloadElement.download = fileName; // 下载后文件名
        document.body.appendChild(downloadElement);
        downloadElement.click(); // 点击下载
        document.body.removeChild(downloadElement); // 下载完成移除元素
        window.URL.revokeObjectURL(href); // 释放掉blob对象
    } else { // IE10+下载
        navigator.msSaveOrOpenBlob(blob, fileName);
    }
};

/**
 * 排课管理-教室借用申请
 */
export function classroomBorrowApply(data) {
  return fetch({
    url: '/api/baseresservice/classroomBorrowPractice/classroomBorrowApply',
    method: 'post',
    data
  });
}

/**
 * 排课管理-查询教室借用 分页查询
 */
export function getClassroomList(data) {
  return fetch({
    url: '/api/baseresservice/classroomBorrowPractice/queryList',
    method: 'post',
    data
  });
}
